﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace WeighClient.Utils
{
    public class RfidApi
    {
        /// <summary>
        ///1.1 TCP参数初始化
        ///功能：通过参数传入，此函数用于计算机的以太网应用配置，初始化一个SOCKET，为建立基于以太网接口的连接做准备。
        /// </summary>
        /// <param name="pHandle">为保存打开的端口句柄</param>
        /// <param name="pHostName">本机的IP地址，仅在网络通讯模式下有效</param>
        /// <param name="nsocketPort">网络SOCKET端口</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_TCPInit")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_TCPInit(out IntPtr pHandle, string pHostName, int nsocketPort);


        /// <summary>
        ///1.2 COM参数初始化
        /// </summary>
        /// <param name="pHandle">为保存打开的端口句柄</param>
        /// <param name="nBusAddr">为总线地址，默认为0</param>
        /// <param name="pComNum">COM1－COM4 仅在COM通讯模式下有效</param>
        /// <param name="nBaud">串口通讯速率</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_COMInit")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_COMInit(out IntPtr pHandle, byte nBusAddr, string pComNum, int nBaud);


        /// <summary>
        /// 1.3 通过参数传入，初始化TCP，为打开连接做准备
        /// </summary>
        /// <param name="pHandle">为保存打开的端口句柄</param>
        /// <param name="nBusAddr">为总线地址</param>
        /// <param name="pUSBNum">COM1－COM4是(COM1-COM4是虚拟的串口，通信时转USB协议)仅在USB通讯模式下有效</param>
        /// <param name="nBaud">串口(USB口)通讯速率</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_USBInit")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_USBInit(out IntPtr pHandle, byte nBusAddr, string pUSBNum, int nBaud);


        /// <summary>
        /// 1.4 打开读写器[创建网络连接]
        /// </summary>
        /// <param name="pHandle">为已经初始化的端口句柄</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_Open")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_Open(IntPtr pHandle);


        /// <summary>
        /// 1.5 关闭读写器
        /// </summary>
        /// <param name="pHandle">为打开的端口句柄</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_Close")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_Close(IntPtr pHandle);


        /// <summary>
        /// 1.6 系统信息配置[设定读写器参数]
        /// </summary>
        /// <param name="pHandle">打开的端口名柄</param>
        /// <param name="nType">系统信息配置类型</param>
        ///0		读写器名称					16字节
        ///1		读写器产品型号			4字节
        ///2  		读写器出厂产品序列号		4字节
        ///3  	 	读写器系统权限码			4字节
        /// <param name="pParm">系统参数</param>
        /// <param name="nLen">true为操作成功, false为操作失败</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_SysInfSet")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_SysInfSet(IntPtr pHandle, byte nType, byte[] pParm, byte nLen);


        /// <summary>
        /// 1.7 系统信息查询[查询读写器参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">要查询的参数类型</param>
        /// <param name="pPara">指向接收读写器参数数据内存的指针</param>
        /// <param name="pLen">pLen指向的内存长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_SysInfQuery")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_SysInfQuery(IntPtr pHandle, byte nType, IntPtr pPara, ref byte pLen);


        /// <summary>
        /// 1.8 工作模式配置
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">要配置的工作模式</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_WorkModeSet")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_WorkModeSet(IntPtr pHandle, byte nType);

        ////////////////////////////////////////////////////
        /// <summary>
        /// 1.9 读写器系统测试[用于测试读写器]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">测试模式</param>
        /// <param name="bAntenna"></param>
        /// <param name="pTestParm">测试模式参数</param>
        /// <param name="nLen">测试模式参数的长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_SysTest")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_SysTest(IntPtr pHandle, byte nType, byte bAntenna, byte[] pTestParm, byte nLen);


        /// <summary>
        /// 2.2.1 参数表操作[用于操作读写器的参数表，包括导入或者导出读写器的系统参数表]  注：操作模式为0x00时，起始地址和操作长度两项参数无意义。
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">参数表操作的操作模式[0,恢复系统参数表为出厂设置;1,导入系统参数表;2,导出系统参数表]</param>
        /// <param name="nStartAddrr">指定操作参数表起始位置</param>
        /// <param name="nLen">指定操作参数表长度</param>
        /// <param name="pData">导出操作时的导出数据</param>
        /// <param name="pDataLen">导出数据长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_ParmOp")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_ParmOp(IntPtr pHandle, byte nType, byte nStartAddrr, byte nLen, byte[] pData, ref byte pDataLen);


        /// <summary>
        /// 2.2.2 载波参数配置[用于配置读写器的载波参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">设置的频率表的参数类型</param>
        /// <param name="nParaLen">设置的频率表的参数长度</param>
        /// <param name="pPara">设置的频率表参数[“参数类型”为跳频表的类型，目前无意义，默认值0x00;“跳频表”为读写器使用的跳频表]</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_RFParaSet")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_RFParaSet(IntPtr pHandle, byte nType, byte nParaLen, byte[] pPara);


        /// <summary>
        /// 2.2.3 载波参数查询[用于查询读写器的载波参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">查询的频率表的参数类型, 目前无意义，默认值0。</param>
        /// <param name="pPara">返回的频率表参数</param>
        /// <param name="pLen">频率表参数长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_RFParaQuery")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_RFParaQuery(IntPtr pHandle, byte nType, byte[] pPara, ref byte pLen);


        /// <summary>
        /// 2.2.4 通讯参数配置[用于配置通讯参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">配置的参数类型</param>
        /// <param name="pPara">读写器的串行总线参数</param>
        /// <param name="nLen">读写器的串行总线参数长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_CommunicatParaSet")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_CommunicatParaSet(IntPtr pHandle, byte nType, ref byte pPara, byte nLen);


        /// <summary>
        /// 2.2.5 通讯参数查询[用于查询读写器的通讯参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">配置的参数类型</param>
        /// <param name="pPara">查询的读写器总线参数</param>
        /// <param name="pLen">总线参数长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_CommunicatParaQuery")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_CommunicatParaQuery(IntPtr pHandle, byte nType, ref byte pPara, ref byte pLen);


        /// <summary>
        /// 2.2.6 网络参数配置[用于配置通讯参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">“类型”为配置的参数类型</param>
        /// <param name="pPara">配置的以太网参数数据</param>
        /// <param name="nLen">参数数据长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_NetParaSet")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_NetParaSet(IntPtr pHandle, byte nType, byte[] pPara, byte nLen);


        /// <summary>
        /// 2.2.7 网络参数查询[用于查询通讯参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">“类型”为配置的参数类型</param>
        /// <param name="pPara">读写器返回的网络参数数据</param>
        /// <param name="pLen">参数数据长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_NetParaQuery")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_NetParaQuery(IntPtr pHandle, byte nType, byte[] pPara, ref byte pLen);


        ////////////////////////////////////////////////////
        /// <summary>
        /// 2.2.8 标签操作参数配置[用于配置标签操作参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">“类型”为配置的参数类型</param>
        /// <param name="pPara">配置的标签操作参数</param>
        /// <param name="pLen"></param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_TagOpParaSet")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_TagOpParaSet(IntPtr pHandle, byte nType, byte[] pPara, byte pLen);


        /// <summary>
        /// 2.2.9 标签操作配置查询[用于查询标签操作参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">“类型”为配置的参数类型</param>
        /// <param name="pPara">指向保存配置的参数的内存指针</param>
        /// <param name="pLen">指向的内存长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_TagOpParaQuery")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_TagOpParaQuery(IntPtr pHandle, byte nType, byte[] pPara, ref byte pLen);


        /// <summary>
        /// 2.2.10 扩展板参数配置[用于配置扩展板参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">配置的标签操作参数类型</param>
        /// <param name="pSendChunnel">配置的标签操作参数</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAATExtendBroadParaSet")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAATExtendBroadParaSet(IntPtr pHandle, byte nType, byte pSendChunnel);


        /// <summary>
        /// 2.2.11 扩展板参数查询[用于查询扩展板参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">配置的标签操作参数类型</param>
        /// <param name="pPara">查询的参数</param>
        /// <param name="pLen">参数数据长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_ExtendBroadParaQuery")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_ExtendBroadParaQuery(IntPtr pHandle, byte nType, byte[] pPara, ref byte pLen);


        /// <summary>
        /// 2.2.12 射频端口参数查询[用于查询读写器的参数表的全部射频端口参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="szAntennaPara">全部射频端口参数</param>
        /// <param name="pLen">参数长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_TotalAntennaParmQuery")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_TotalAntennaParmQuery(IntPtr pHandle, byte[] szAntennaPara, ref byte pLen);


        /// <summary>
        /// 2.2.13 指定射频端口参数查询[用于查询读写器的参数表的射频端口号参数]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号 1~4 </param>
        /// <param name="pAntennaEnable">端口使能,0为禁止,1为允许</param>
        /// <param name="pAntennaPower">输出功率,单位为dBm</param>
        /// <param name="pAntennaQueryTime">轮循该端口的时候,单位为MS</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_AntennaParmQuery")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_AntennaParmQuery(IntPtr pHandle, byte nAntenna, ref byte pAntennaEnable, ref byte pAntennaPower, ref byte pAntennaQueryTime);


        /// <summary>
        /// 2.2.14 射频端口参数配置[用于配置读写器的参数表的射频端口参数 (谨用)]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="pPara">配置读写器的参数表的射频端口参数</param>
        /// <param name="nLen">参数长度, 一般为12字节</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_AntennaParmSet")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_AntennaParmSet(IntPtr pHandle, byte[] pPara, byte nLen);


        /// <summary>
        /// 2.2.15 指定射频端口使能配置[用于配置读写器指定射频端口使能]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">射频端口号</param>
        /// <param name="nEnable">使能设置</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_SetAntennaPortEnable")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_SetAntennaPortEnable(IntPtr pHandle, byte nAntenna, byte nEnable);


        /// <summary>
        /// 2.2.16 指定射频端口功率配置[用于配置读写器的指定射频端口功率]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">射频端口号</param>
        /// <param name="nPower">设置功率</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_SetAntennaPower")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_SetAntennaPower(IntPtr pHandle, byte nAntenna, byte nPower);


        /// <summary>
        /// 2.2.17 指定射频端口轮巡时间配置[用于配置读写器的指定射频端口轮巡时间]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">射频端口号</param>
        /// <param name="nTime">设置轮巡时间, 工作时间=轮巡时间 * 20ms</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_SetAntennaTime")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_SetAntennaTime(IntPtr pHandle, byte nAntenna, byte nTime);


        /// <summary>
        /// 2.2.18 关闭功放 (关闭读卡)[用于关闭功放,主要用在关闭读卡操作]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_PowerOff")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_PowerOff(IntPtr pHandle);


        ////////////////////////////////////////////////////
        /// <summary>
        /// 2.2.19 获取出错信息[用于关闭功放,主要用在关闭读卡操作]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="szMsg">返回错误信息</param>
        /// <param name="nLen"></param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_GetErrorMessage")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_GetErrorMessage(IntPtr pHandle, byte[] szMsg, int nLen);


        /// <summary>
        /// 2.3.1 载波操作[用于控制读写器的载波，打开或关闭载波并由指定端口输出]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType"></param>
        /// <param name="nPort">打开的载波端口</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_CarrierWaveOp")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_CarrierWaveOp(IntPtr pHandle, byte nType, byte nPort);


        /// <summary>
        /// 2.3.2 IO输出操作[用于控制读写器的IO输出操作]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nPort">输出端口[0,所有端口;1,端口1;2,端口2;3,端口3;4,端口4]</param>
        /// <param name="nState">输出状态[0,输出低电平;1,输出高电平;2,输出正脉冲;3,输出负脉冲]</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_IOOperate")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_IOOperate(IntPtr pHandle, byte nPort, byte nState);


        /// <summary>
        /// 2.3.3 IO输入查询指令[用于查询读写器扩展板的IO输入状态]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="pState">输入端口的电平状态</param>
        ///		pState:		输入端口的电平状态
        ///					域说明：端口状态
        ///				位		Bit7	Bit 6	Bit 5	Bit 4	Bit 3	Bit 2	Bit 1	Bit 0
        ///				定义	保留	保留	保留	保留	保留	保留	端口2	端口1
        ///				端口状态：	0 :低电平
        ///							1:高电平
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_IOStateQuery")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_IOStateQuery(IntPtr pHandle, ref byte pState);


        ////////////////////////////////////////////////////
        /// <summary>
        /// 2.4.1 标签选择配置[用来标签选择]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nType">为匹配类型</param>
        /// <param name="nStartAddr">为匹配数据的起始字节地址</param>
        /// <param name="nDataBite">为匹配掩码, Data 为8字节进行匹配的数据	</param>
        /// <param name="btData"></param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6BTagSelect")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6BTagSelect(IntPtr pHandle, byte nType, byte nStartAddr, byte nDataBite, byte[] btData);


        /// <summary>
        /// 2.4.2 读标签UID码命令[发送读取标签UID码命令]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">为天线号</param>
        /// <param name="nType">为操作模式</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        //		操作模式:
        //		00：读写器将读取到的所有的标签EPC码全部上传到上位机并要求上位机接收后给予读写器"返回数据确认” 
        //		01：读写器将读取到的所有的标签EPC码全部上传到上位机并不要求上位机接收后给予读写器"返回数据确认”，到上位机下发"关功放"命令后才停止读标签EPC码。
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6BReadUIDCode")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6BReadUIDCode(IntPtr pHandle, byte nAntenna, byte nType);


        /// <summary>
        /// 2.4.3 接收标签UID码[启动接收标签UID ]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">为天线号</param>
        /// <param name="pUIDData">为UID数据</param>
        /// <param name="nUIDLen">为UID数据长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6BRevUIDMsg")]
        public static extern int SAAT_6BRevUIDMsg(IntPtr pHandle, out byte nAntenna, byte[] pUIDData,
                                                out byte nUIDLen);

        /// <summary>
        /// 2.4.4 读标签数据[用于读取标签数据]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">操作模式</param>
        /// <param name="pTagID">8字节标签ID号</param>
        /// <param name="nStartAddr">数据区的首地址</param>
        /// <param name="nReadLen">读取长度</param>
        /// <param name="pdata">数据内容</param>
        /// <param name="dataLen">内容长度</param>
        /// <returns></returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6BReadUserData")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6BReadUserData(IntPtr pHandle, byte nAntenna, byte nType, byte[] pTagID,
            byte nStartAddr, byte nReadLen, byte[] pdata, byte dataLen);


        /// <summary>
        /// 2.4.5 写标签数据[用于写标签数据]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">操作模式</param>
        /// <param name="pTagID">8字节标签ID号</param>
        /// <param name="nStartAddrr">写入数据区的首地址</param>
        /// <param name="pValue">写入的数据</param>
        /// <param name="nLen">写入数据的数据长度返回值</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6BWriteUserData")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6BWriteUserData(IntPtr pHandle, byte nAntenna, byte nType, byte[] pTagID,
            byte nStartAddrr, byte[] pValue, ref byte nLen);


        /// <summary>
        /// 2.4.6 锁标签数据[用于锁标签数据]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">操作模式</param>
        /// <param name="pTagID">8字节的标签ID号</param>
        /// <param name="nStartAddrr">锁定数据区的首地址 ,8~224字节</param>
        /// <param name="nLen">锁定数据区的数据长度, 长度+起始地址不应超出224</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6BTagLock")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6BTagLock(IntPtr pHandle, byte nAntenna, byte nType, byte[] pTagID, byte nStartAddrr, byte nLen);


        /// <summary>
        /// 2.5.1 标签选择[用于选择标签数据]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nBank">指定匹配的数据Bank</param>
        /// <param name="nStartAddr">指定匹配的Bank数据的数据起始地址</param>
        /// <param name="MaskBit">指定匹配数据的匹配比特数</param>
        /// <param name="btData">指定匹配数据</param>
        /// <param name="Datalength">匹配数据长度</param>
        /// <param name="nSessionZone">指定匹配数据的会话区</param>
        /// <param name="nActiveFlag">指定匹配数据的活动标志</param>
        /// <param name="nCutFlag">指定匹配数据是否使用截断标志</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CTagSelect")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CTagSelect(IntPtr pHandle, byte nBank, byte nStartAddr, byte MaskBit,
            byte[] btData, byte Datalength, byte nSessionZone, byte nActiveFlag, byte nCutFlag);


        /// <summary>
        /// 2.5.2 发送读EPC码命令[用于发读EPC码命令]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">操作模式</param>
        /// <param name="nTagCount">同时预计读取标签数, 预计工作环境中一次需要同时读取的最大标签数，设计为1到255张，实际读取数超过500张</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        //		操作模式：
        //		00：对同一个标签的EPC码读写器只向上位机返回一次，并要求上位机接收后给予读写器"返回数据确认"，
        //		01：读写器将读取到的所有的标签EPC码全部上传到上位机并不要求上位机接收后给予读写器"返回数据确认"，直到上位机下发"关功放"命令后才停止读标签EPC码。）
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CReadEPCCode")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CReadEPCCode(IntPtr pHandle, byte nAntenna, byte nType,
            byte nTagCount);


        /// <summary>
        /// 2.5.3 接收EPC码命令[用于接收EPC码]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="pEPCData">EPC数据</param>
        /// <param name="nEPCLen">EPC数据长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CRevEPCMsg")]
        public static extern int SAAT_6CRevEPCMsg(IntPtr pHandle, out byte nAntenna, byte[] pEPCData,
            out byte nEPCLen);


        /// <summary>
        /// 2.5.4 读TID码命令[用于读取TID码]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">操作模式</param>
        /// <param name="nTagCount">同时预计读取标签数</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        //		操作模式：
        //		00：对同一个标签的TID码读写器只向上位机返回一次，并要求上位机接收后给予读写器"返回数据确认"
        //		01：读写器将读取到的所有的标签TID码全部上传到上位机并不要求上位机接收后给予读写器"返回数据确认"，直到上位机下发"关功放"命令后才停止读标签TID码。
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CReadTIDCode")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CReadTIDCode(IntPtr pHandle, byte nAntenna, byte nType, byte nTagCount);


        /// <summary>
        /// 2.5.5 接收TID码命令[用于接收TID码]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="pTIDData">TID数据</param>
        /// <param name="nTIDLen">TID数据长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CRevTIDMsg")]
        public static extern int SAAT_6CRevTIDMsg(IntPtr pHandle, out byte nAntenna, byte[] pTIDData, out byte nTIDLen);


        /// <summary>
        /// 2.5.6 写EPC码[用于写EPC码]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">操作模式</param>
        /// <param name="pAccessPWD">4字节访问密码</param>
        /// <param name="pWriteData">写入标签的EPC码的数据</param>
        /// <param name="nLen">写入标签的EPC码的长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CWriteEPCCode")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CWriteEPCCode(IntPtr pHandle, byte nAntenna, byte nType,
            byte[] pAccessPWD, byte[] pWriteData, byte nLen);


        /// <summary>
        /// 2.5.7  读用户数据区[读取用户数据返回]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="StartAddr">读取标签数据区的首地址</param>
        /// <param name="nLength">读取标签数据区的数据长度</param>
        /// <param name="UserData">读取到的数据区数据</param>
        /// <param name="nDataLen">读取到的数据区数据长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CReadUserData")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CReadUserData(IntPtr pHandle, byte nAntenna, UInt32 StartAddr,
            UInt32 nToReadLen, UInt32 nWaitTime, byte[] UserData, ref UInt32 pDataLen);


        /// <summary>
        /// 2.5.8 写用户数据区[写用户数据信息]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">操作类型</param>
        /// <param name="pAccessPWD">4字节访问密码</param>
        /// <param name="nStartAddr">标签数据区的首地址</param>
        /// <param name="pWriteData">写入标签的用户数据区的数据</param>
        /// <param name="nLen">写入标签的用户数据区的长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CWriteUserData")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CWriteUserData(IntPtr pHandle, byte nAntenna, byte nType,
            byte[] pAccessPWD, UInt32 nStartAddr, UInt32 nWaitTime, byte[] pWriteData, ref UInt32 nLen);


        /// <summary>
        /// 2.5.9 块写Bank数据[块写Bank数据]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">操作类型</param>
        /// <param name="pAccessPWD">4字节访问密码</param>
        /// <param name="nBank">写入标签数据的Bank</param>
        /// <param name="pWriteData">写入标签的用户数据区的数据</param>
        /// <param name="nLen">写入标签的用户数据区的长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CWriteBankData")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CWriteBankData(IntPtr pHandle, byte nAntenna, byte nType, byte[] pAccessPWD,
            byte nBank, byte[] pWriteData, byte nLen);


        /// <summary>
        /// 2.5.10 块擦Bank数据[块擦Bank数据]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">操作类型</param>
        /// <param name="pAccessPWD">4字节访问密码</param>
        /// <param name="nBank">写入标签数据的Bank</param>
        /// <param name="nStartAddr">擦出标签的数据区的首地址</param>
        /// <param name="nLen">为擦出标签的数据区的长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CClearBankData")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CClearBankData(IntPtr pHandle, byte nAntenna, byte nType, byte[] pAccessPWD,
            byte nBank, byte nStartAddr, byte nLen);


        /// <summary>
        /// 2.5.11 配置访问密码[设置用户访问密码信息]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">操作类型</param>
        /// <param name="pOrgPWD">4字节旧访问密码,默认为8个零</param>
        /// <param name="pNewPWD">4字节新访问密码</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        //说明：	标签出厂默认的访问密码为8个零。
        //			如果密码所在Bank未锁定，全零的密码也可执行写操作（细节参见EPC协议）。
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CAccessPWDSet")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CAccessPWDSet(IntPtr pHandle, byte nAntenna, byte nType, byte[] pOrgPWD, byte[] pNewPWD);


        /// <summary>
        /// 2.5.12 销毁密码[设置用户销毁密码信息]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">为操作类型</param>
        /// <param name="pAccessPWD">标签访问密码</param>
        /// <param name="pDestroyPWD">标签销毁密码, 默认的销毁密码为8个零</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CDestroyPWDSet")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CDestroyPWDSet(IntPtr pHandle, byte nAntenna, byte nType, byte[] pAccessPWD, byte[] pDestroyPWD);


        /// <summary>
        /// 2.5.13 标签锁状态配置[标签锁状态配置]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="pAccessPWD">标签访问密码</param>
        /// <param name="nType">锁操作类型</param>
        /// <param name="nBank">执行锁操作的Bank </param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CTagLock")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CTagLock(IntPtr pHandle, byte nAntenna, byte[] pAccessPWD, byte nType, byte nBank);


        /// <summary>
        /// 2.5.14 标签销毁[销毁标签信息]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="pDestroyPWD">标签销毁密码</param>
        /// <param name="pEPC">标签EPC码</param>
        /// <param name="nEPCLen">EPC长度</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CTagKill")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CTagKill(IntPtr pHandle, byte nAntenna, byte[] pDestroyPWD, byte[] pEPC, int nEPCLen);


        /// <summary>
        /// 2.5.15 EAS标志配置[EAS标志配置]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">锁操作类型</param>
        /// <param name="pAccessPwd">标签访问密码</param>
        /// <param name="nEASFlag">EAS标志配置[0,取消EAS比特位;1,设置EAS比特位]</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CEASFlagSet")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CEASFlagSet(IntPtr pHandle, byte nAntenna, byte nType, byte[] pAccessPwd, int nEASFlag);


        /// <summary>
        /// 2.5.16 启动EAS监控[启动EAS监控]
        /// </summary>
        /// <param name="pHandle">打开的端口句柄</param>
        /// <param name="nAntenna">天线号</param>
        /// <param name="nType">ESA设置操作模式</param>
        /// <param name="pAccesssPwd">标签访问密码</param>
        /// <param name="nSetEAS">EAS监控操作控制</param>
        /// <param name="nMonitorType">EAS监控配置[0x00,结束EAS监控;0x01,启动EAS监控]</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_6CEASMonitorEnable")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_6CEASMonitorEnable(IntPtr pHandle, byte nAntenna, byte nType, byte[] pAccesssPwd, byte nSetEAS, byte nMonitorType);



        /// <summary>
        /// 0.0.1 API版本信息
        /// </summary>
        /// <param name="pHandle">为保存打开的端口句柄</param>
        /// <param name="copyright">版本信息</param>
        /// <returns>true为操作成功, false为操作失败</returns>
        [DllImport("RFIDAPI.dll", EntryPoint = "SAAT_Copyright")]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool SAAT_Copyright(out IntPtr pHandle, StringBuilder copyright);
    }
}
